package com.activiti.tool;

import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngines;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.repository.NativeProcessDefinitionQuery;
import org.activiti.engine.repository.ProcessDefinition;
import org.activiti.engine.repository.ProcessDefinitionQuery;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.List;

/**
 * 查询流程定义
 *
 * @author ldanniel
 */
public class QuerProcessDefinition {
    private static final Logger logger = LoggerFactory.getLogger(QuerProcessDefinition.class);

    public static void main(String[] args) {
        //创建
        ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
        //获取RepositoryService
        RepositoryService repositoryService = processEngine.getRepositoryService();
        //获取ProcessDefinitionQuery对象
        ProcessDefinitionQuery processDefinitionQuery = repositoryService.createProcessDefinitionQuery();
        //流程定义信息列表
        List<ProcessDefinition> definitionList = processDefinitionQuery.processDefinitionKey("myEvection")
                .orderByProcessDefinitionVersion()
                .desc()
                .list();
        definitionList.forEach((value) -> {
            logger.info("流程定义的名称【{}】", value.getName());
            logger.info("流程定义的id【{}】", value.getId());
            logger.info("流程定义的id【{}】", value.getId());
            logger.info("流程定义的key【{}】", value.getKey());
            logger.info("流程定义的版本【{}】", value.getVersion());
            logger.info("流程部署id【{}】", value.getDeploymentId());
        });
    }
}
